import { useTable, LIST_TYPE } from '@crud/index';
import { getMajorCustomerList as getList } from '@/api/crm-kgj/user';
import { formatParamsSelectVal, toolOptions2Map } from '@/utils';

export const channelOptions = [
  { value: -1, label: '不限' },
  { value: 1, label: '官网' },
  { value: 2, label: '投放页' }
];

const channelMap = toolOptions2Map(channelOptions);
export const useTableList = (options: any = {}) => {
  const columns = [
    {
      label: '姓名',
      prop: 'name',
      align: 'center',
      width: 100
    },
    {
      label: '公司',
      prop: 'company_name',
      showOverflowTooltip: true,
      minWidth: 180,
      align: 'center'
    },
    {
      label: '手机号',
      prop: 'mobile',
      align: 'center',
      width: 122
    },
    {
      label: '微信号',
      prop: 'wx_number',
      align: 'center',
      width: 180,
      showOverflowTooltip: true
    },
    {
      label: '渠道',
      prop: 'channel',
      align: 'center',
      render: (e) => channelMap[e.row.channel] ?? '-',
      width: 100
    },
    {
      label: '提交时间',
      prop: 'add_time',
      type: 'dateTime',
      align: 'center',
      width: 177
    },
    {
      label: '需求描述',
      prop: 'demand',
      align: 'center',
      showOverflowTooltip: true,
      width: 300
    },
    {
      label: '备注',
      prop: 'remark',
      align: 'center',
      showOverflowTooltip: true,
      width: 200
    },
    {
      label: '操作',
      align: 'center',
      render: 'actions',
      width: 160,
      fixed: 'right'
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {
      channel: -1
    },
    columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.begin = begin;
        params.end = end;
      }
      return {
        ...params,
        ...formatParamsSelectVal([['channel', -1]], params)
      };
    },
    getList
  });
};
